package com.rpframework.website.daole.act.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.rpframework.core.BaseAct;
import com.rpframework.core.api.FileService;
import com.rpframework.core.utils.DictionarySettingUtils;
import com.rpframework.core.utils.MessageFormatter;
import com.rpframework.core.utils.TagUtils;
import com.rpframework.module.common.domain.City;
import com.rpframework.module.common.domain.County;
import com.rpframework.module.common.service.CityService;
import com.rpframework.module.common.service.CountyService;
import com.rpframework.module.common.service.SMSService;
import com.rpframework.utils.AlgorithmEnum;
import com.rpframework.utils.AlgorithmUtils;
import com.rpframework.utils.DateUtils;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.daole.domain.Car;
import com.rpframework.website.daole.domain.Station;
import com.rpframework.website.daole.domain.User;
import com.rpframework.website.daole.exception.APICodeException;
import com.rpframework.website.daole.service.CarService;
import com.rpframework.website.daole.service.StationService;
import com.rpframework.website.daole.service.UserService;

@Controller
@RequestMapping("/")
public class IndexAct extends BaseAct {
	@Resource UserService userService;
	@Resource SMSService smsService;
	@Resource FileService fileService;
	@Resource CityService cityService;
	
	@Resource CountyService countyService;
	@Resource StationService stationService;
	@Resource CarService carService;
	
	// 首页
	@RequestMapping("/index")
	public String index(@RequestParam(value="cityCode",required=false) String cityCode,Map<Object,Object> model,HttpSession session){
		String sessionCityCode = getSessionCityCode(session);
		if(StringUtils.isBlank(sessionCityCode) && StringUtils.isBlank(cityCode)){
			cityCode = "330100";
		} else if (StringUtils.isNotBlank(cityCode)) {
			session.setAttribute(SESSION_CITY_CODE_KEY,cityCode);
		}
		cityCode = sessionCityCode = getSessionCityCode(session);
		
		List<City> cityList=cityService.getCityListWithState(1);
		model.put("cityList", cityList);
		model.put("currCity", getCurrCity(sessionCityCode));
		return "/web/index/index";
	}
		
	@RequestMapping("/regist")
	public String regist(Map<Object,Object> model,@RequestParam(value="recommendContact",required=false) String recommendContact,
		HttpSession session){
		List<City> cityList=cityService.getCityListWithState(1);
		model.put("cityList", cityList);

		model.put("currCity", getCurrCity(getSessionCityCode(session)));
		return "/web/regist/0.0.2zhuce";
	}
	
	
	/**
	 * 验证手机是否存在
	 * @param contact
	 * @return
	 */
	@RequestMapping(value="/check_contact_is_exist/{contact}")
	public @ResponseBody JsonElement valPhone(@PathVariable("contact") String contact){
		JsonObject json = new JsonObject();
		User user = userService.findUserByContact(contact); // 根据手机号码查找用户
		if(user == null){ // user 为空 说明该手机号码没有被使用
			json.addProperty("succ", true);
		} else { // 该手机号码被使用
			json.addProperty("error", false);
		} 
		return json;
	}
	
	
	
	/**
	 * 检验密码
	 * @param password
	 * @param qpassword
	 * @return
	 */
	@RequestMapping("/check_pwd/{password}/{qpassword}")
	public @ResponseBody JsonElement checkPwd(@PathVariable String password,@PathVariable String qpassword){
		JsonObject json = new JsonObject();
		if(password.length() < 6 || qpassword.length() < 6){
			json.addProperty("msg", "密码长度不能小与6位!");
		} else if(!password.equals(qpassword) && password.length() > 6){
			json.addProperty("msg", "密码不一致!");
		} else {
			json.addProperty("succ", true);
		}
		return json;
	}
	
	
	/**
	 * 发送注册验证码
	 * @param contact 手机号码
	 * @return
	 */
	@RequestMapping("/sendsms_for_regist/{contact}")
	public @ResponseBody JsonElement sendSMSForRegist(@PathVariable String contact) {
		
		if(StringUtils.isEmpty(contact)) {
			throw new APICodeException(-1, "非法参数!");
		}
		if(userService.findUserByContact(contact) != null){
			throw new APICodeException(-2, "该手机已被使用!");
		}
		String verifyCode = String.valueOf(NumberUtils.random(6));
		String sendContent = DictionarySettingUtils.getParameterValue("sendsms.regist");
		if(StringUtils.isBlank(sendContent)) {
			sendContent =  "本次注册验证码:{}，请牢记";
		}
		sendContent = MessageFormatter.format(sendContent, verifyCode);
		
		boolean flag = smsService.sendSMS(1, contact, verifyCode, sendContent);
		if(!flag) {
			throw new APICodeException(-3, "短信发送失败!");
		}
		JsonObject json = new JsonObject();
		json.addProperty("succ", true);
		return json;
	}
	
	
	/**
	 * 发送修改密码验证码
	 * @param contact
	 * @return
	 */
	@RequestMapping("/sendsms_for_forget_password/{contact}")
	public @ResponseBody JsonElement sendSMSForForgetPassowrd(@PathVariable(value="contact") String contact) {
		if(StringUtils.isBlank(contact)) {
			throw new IllegalArgumentException("非法参数!");
		}
		
		String verifyCode = String.valueOf(NumberUtils.random(6));
		String sendContent = DictionarySettingUtils.getParameterValue("sendsms.forget_passowrd");
		if(StringUtils.isBlank(sendContent)) {
			sendContent =  "本次重置密码验证码:{}，请牢记";
		}
		sendContent = MessageFormatter.format(sendContent, verifyCode);
		
		boolean flag = smsService.sendSMS(2, contact, verifyCode, sendContent);
		if(!flag) {
			throw new IllegalArgumentException("短信发送失败!");
		}
		JsonObject json = new JsonObject();
		json.addProperty("succ", true);
		return json;
	}
	
	
	
	
	// 验证手机验证码
		@RequestMapping("/doregist")
		public String valCode(@ModelAttribute User user,@RequestParam(value="qpassword") String qpassword,
				@RequestParam(value="valCode") String valCode,Map<Object, Object> model,
				RedirectAttributes attr,HttpSession session){
			if(StringUtils.isBlank(user.getContact()) || 
					StringUtils.isBlank(user.getPassword()) ||
					StringUtils.isBlank(qpassword) ||
					StringUtils.isBlank(valCode)){
				throw new IllegalArgumentException("非法参数");
			}
			User rUser = userService.findUserByContact(user.getContact());
			if(rUser != null) {
				setErrorMsg("该手机号码已被使用", attr);
				return redirect("/regist");
			}
			if(!smsService.checkVerifyCode(1, user.getContact(), valCode)) {
				setErrorMsg("验证码错误", attr);
				return redirect("/regist");
			}
			
			String password = AlgorithmUtils.encodePassword(user.getPassword(), AlgorithmEnum.MD5);
			user.setPassword(password);
			userService.doSaveOrUpdate(user);
			
			model.put("contact",user.getContact());
			List<City> cityList=cityService.getCityListWithState(1);
			model.put("cityList", cityList);

			model.put("currCity", getCurrCity(getSessionCityCode(session)));
			
			return "/web/regist/0.0.3zhuce_NO.2";
		}
		
		
		
		@RequestMapping("/toregist2")
		public String valCode2(Map<Object, Object> model,@RequestParam(value="contact") String contact,
				
				RedirectAttributes attr,HttpSession session){
			model.put("contact",contact);
			
			return "/web/regist/0.0.3zhuce_NO.2";
		}
		
		
		

		@RequestMapping("/doregist2")
		public String doSaveOrUpdate2(@RequestParam(value="cardFrontImgFile", required=false) CommonsMultipartFile cardFrontImgFile,
				@RequestParam(value="cardBackImgFile", required=false) CommonsMultipartFile cardBackImgFile,
				@RequestParam(value="driverLicenseFrontImgFile", required=false) CommonsMultipartFile driverLicenseFrontImgFile,
				@RequestParam(value="driverLicenseBackImgFile", required=false) CommonsMultipartFile driverLicenseBackImgFile,
				
				@ModelAttribute User user, HttpSession session, HttpServletRequest request,
				@RequestParam(value="input_area") Integer input_area,Map<Object, Object> model,
				RedirectAttributes attr){
			
			
			if(!NumberUtils.isValid(input_area)) {
				throw new APICodeException(-1, "非法参数!");
			}else{
				user.setAreaId(input_area);
			}
			
			User newUser=userService.findUserByContact(user.getContact());
			newUser.setRealName(user.getRealName());
			newUser.setAreaId(user.getAreaId());
			newUser.setDriverLicenseNo(user.getDriverLicenseNo());
			
			if(cardFrontImgFile.getSize() > 0) {
				try {
					String relativelyPath = "resources/user/" + DateUtils.nowDate(DateUtils.YYYYMMDDHHMMSS) + NumberUtils.random() + "." + FilenameUtils.getExtension(cardFrontImgFile.getOriginalFilename());
					fileService.saveFile(cardFrontImgFile.getInputStream(), relativelyPath);
					//slideshow.setIcon(relativelyPath);
					newUser.setCardFrontImgUrl(relativelyPath);
				} catch (Exception e) {
					throw new IllegalArgumentException("文件上传失败，原因:" + e.getLocalizedMessage());
				}
			}
			

			if(cardBackImgFile.getSize() > 0) {
				try {
					String relativelyPath = "resources/user/" + DateUtils.nowDate(DateUtils.YYYYMMDDHHMMSS) + NumberUtils.random() + "." + FilenameUtils.getExtension(cardBackImgFile.getOriginalFilename());
					fileService.saveFile(cardBackImgFile.getInputStream(), relativelyPath);
					//slideshow.setIcon(relativelyPath);
					newUser.setCardBackImgUrl(relativelyPath);
				} catch (Exception e) {
					throw new IllegalArgumentException("文件上传失败，原因:" + e.getLocalizedMessage());
				}
			}
			
			
			if(driverLicenseFrontImgFile.getSize() > 0) {
				try {
					String relativelyPath = "resources/user/" + DateUtils.nowDate(DateUtils.YYYYMMDDHHMMSS) + NumberUtils.random() + "." + FilenameUtils.getExtension(driverLicenseFrontImgFile.getOriginalFilename());
					fileService.saveFile(driverLicenseFrontImgFile.getInputStream(), relativelyPath);
					//slideshow.setIcon(relativelyPath);
					newUser.setDriverLicenseFrontImgUrl(relativelyPath);
				}catch (Exception e) {
					throw new IllegalArgumentException("文件上传失败，原因:" + e.getLocalizedMessage());
				}	
					 
			}
			
			

			if(driverLicenseBackImgFile.getSize() > 0) {
				try {
					String relativelyPath = "resources/user/" + DateUtils.nowDate(DateUtils.YYYYMMDDHHMMSS) + NumberUtils.random() + "." + FilenameUtils.getExtension(driverLicenseBackImgFile.getOriginalFilename());
					fileService.saveFile(driverLicenseBackImgFile.getInputStream(), relativelyPath);
					//slideshow.setIcon(relativelyPath);
					newUser.setDriverLicenseBackImgUrl(relativelyPath);
				}catch (Exception e) {
					throw new IllegalArgumentException("文件上传失败，原因:" + e.getLocalizedMessage());
				}	
					 
			}
			
			userService.doSaveOrUpdate(newUser);
			if(NumberUtils.isValid(user.getId())) {//update
				setInfoMsg("更新操作成功！", attr);
			} else {//insert
				setInfoMsg("新增操作成功！", attr);
			}
			
			
			
			model.put("contact",user.getContact());
			List<City> cityList=cityService.getCityListWithState(1);
			model.put("cityList", cityList);

			model.put("currCity", getCurrCity(getSessionCityCode(session)));
			
			return "/web/regist/0.0.4zhuce_NO.3";
		}
		
		
		
		@RequestMapping("/dologin")
		public String login(@RequestParam(value="contact") String contact,@RequestParam(value="password") String password,
				RedirectAttributes attr,Map<Object, Object> model, HttpSession session){

			if(StringUtils.isBlank(contact) || StringUtils.isBlank(password)) {
				setErrorMsg("非法参数", attr); // setErrorMsg 、 setInfoMsg 需要 redirect 才起作用
				return redirect("/index");
			}
			
			User lUser = userService.findUserByContact(contact);
			if(lUser == null) {
				setErrorMsg("账号"+contact+"不存在!", attr);
				return redirect("/index");
			}
				password = AlgorithmUtils.encodePassword(password, AlgorithmEnum.MD5);
			if (!StringUtils.equals(password, lUser.getPassword())) {
				setErrorMsg("密码错误", attr);
				return redirect("/index");
			}
			
			if (!lUser.getState().equals(1)) {
				setErrorMsg("状态异常", attr);
				return redirect("/index");
			}
			session.setAttribute(SESSION_USER_KEY, lUser);
			User user = (User) session.getAttribute(SESSION_USER_KEY);
			session.setAttribute(SESSION_USER_KEY, user);
			model.put("sessionUser", lUser);
			
			String msgStr = MessageFormatter.format("/index.html?cityCode={}", "330100");
			return redirect(msgStr);
		}
		
		
		/**
		 * 获取当前的城市
		 * @param cityCode
		 * @return
		 */
		public City getCurrCity(String cityCode){
			if(StringUtils.isBlank(cityCode)){
				cityCode = "330100";
			}
			if(cityService.select(cityCode) == null){
				throw new IllegalArgumentException("不存在的城市");
			}
			return cityService.select(cityCode);
		}
		
		
		
		/**
		 * 验证忘记密码验证码
		 * @param contact
		 * @param valCode
		 * @param attr
		 * @param model
		 * @param session
		 * @return
		 */
		@RequestMapping("/doforget")
		public String doforget(@RequestParam(value="contact") String contact,@RequestParam(value="valCode") String valCode,
				RedirectAttributes attr,Map<Object, Object> model, HttpSession session){
//			String sessionCityCode = getSessionCityCode(session);
//			if(StringUtils.isBlank(sessionCityCode) && StringUtils.isBlank(cityCode)){
//				cityCode = "330100";
//			} else if (StringUtils.isNotBlank(cityCode)) {
//				session.setAttribute(SESSION_CITY_CODE_KEY,cityCode);
//			}
//			cityCode = sessionCityCode = getSessionCityCode(session);
			
//			
//			User user = userService.findUserByContact(contact);
//			if(user == null){
//				setErrorMsg("不存在的手机号：" + contact, attr);
//				return redirect("/forget");
//			}
//			if(!smsService.checkVerifyCode(2, contact, valCode)) {
//				setErrorMsg("验证码错误", attr);
//				return redirect("/forget");
//			}
//			model.put("contact", contact);
//			List<City> cityList=cityService.getCityListWithState(1);
//			model.put("cityList", cityList);
//			model.put("currCity", getCurrCity(sessionCityCode));
//			return redirect("/web/forget/0.0.1wangjimima2");
//			return "/web/forget/0.0.1wangjimima2";
//			return redirect(msgStr);
			
			User user = userService.findUserByContact(contact);
			if(user == null){
				setErrorMsg("不存在的手机号：" + contact, attr);
				return redirect("/forget");
			}
			if(!smsService.checkVerifyCode(2, contact, valCode)) {
				setErrorMsg("验证码错误", attr);
				return redirect("/forget");
			}
			String msgStr = MessageFormatter.format("/reset.html?contact={}", contact);
			return redirect(msgStr);
			
			
		}
		
		/**
		 * 修改密码
		 * @param request
		 * @param model
		 * @param session
		 * @param attr
		 * @return
		 */
		@RequestMapping("/doreset")
		public String doreset(HttpServletRequest request, Map<Object,Object> model,HttpSession session,RedirectAttributes attr){
			String contact = request.getParameter("contact");
			String password = request.getParameter("password");
			String qpassword = request.getParameter("qpassword");
			if(StringUtils.isBlank(contact) || StringUtils.isBlank(password) || StringUtils.isBlank(qpassword)) {
				throw new IllegalArgumentException("非法参数!");
			}
			User user = userService.findUserByContact(contact);
			if(user == null){
				setErrorMsg("不存在的手机号：" + contact, attr);
				String msgStr = MessageFormatter.format("/reset.html?contact={}", contact);
				return redirect(msgStr);
			}
			password = AlgorithmUtils.encodePassword(password, AlgorithmEnum.MD5);
			qpassword = AlgorithmUtils.encodePassword(qpassword, AlgorithmEnum.MD5);
			if(!password.equals(qpassword)){
				setErrorMsg("两次密码不一致", attr);
				String msgStr = MessageFormatter.format("/reset.html?contact={}", contact);
				return redirect(msgStr);
			}
			if(StringUtils.equals(user.getPassword(), password)) {
				setErrorMsg("与原密码一致无需修改", attr);
				String msgStr = MessageFormatter.format("/reset.html?contact={}", contact);
				return redirect(msgStr);
			}
			user.setPassword(password);
			userService.update(user);
			
			model.put("currCity", getCurrCity(getSessionCityCode(session)));
			List<City> cityList=cityService.getCityListWithState(1);
			model.put("cityList", cityList);
			
			return "/web/forget/0.0.1wangjimima3";
		}
		
		
		// 忘记密码
		@RequestMapping("/forget")
		public String forget(Map<Object,Object> model,HttpSession session){
			
			List<City> cityList=cityService.getCityListWithState(1);
			model.put("cityList", cityList);
			model.put("currCity", getCurrCity(getSessionCityCode(session)));
			return "/web/forget/0.0.1wangjimima1";
		}
		
		// 重置密码
		@RequestMapping("/reset")
		public String forget(@RequestParam(value="contact") String contact, Map<Object,Object> model,HttpSession session){
			model.put("contact", contact);
			model.put("currCity", getCurrCity(getSessionCityCode(session)));
			List<City> cityList=cityService.getCityListWithState(1);
    		model.put("cityList", cityList);

			return "/web/forget/0.0.1wangjimima2";
		}
		
		// 重置成功
		@RequestMapping("/success")
		public String success(Map<Object,Object> model,HttpSession session){
						model.put("currCity", getCurrCity(getSessionCityCode(session)));
			
			return "/web/success";
		}
		
		
		
	
//		/**
//		 * 验证手机是否存在
//		 * @param contact
//		 * @return
//		 */
//		@RequestMapping(value="/check_contact_is_exist/{contact}")
//		public @ResponseBody JsonElement valPhone(@RequestParam(value="cityCode",required=false) String cityCode,HttpSession session,
//				@PathVariable("contact") String contact){
//			String sessionCityCode = getSessionCityCode(session);
//			if(StringUtils.isBlank(sessionCityCode) && StringUtils.isBlank(cityCode)){
//				cityCode = "330100";
//			} else if (StringUtils.isNotBlank(cityCode)) {
//				session.setAttribute(SESSION_CITY_CODE_KEY,cityCode);
//			}
//			cityCode = sessionCityCode = getSessionCityCode(session);
//			
////			List<City> cityList=cityService.getCityListWithState(1);
////			model.put("cityList", cityList);
////			model.put("currCity", getCurrCity(sessionCityCode));
////			return "/web/index/index";
//			
//			List<County> countyList=
//			
//			
//			JsonObject json = new JsonObject();
//			User user = userService.findUserByContact(contact); // 根据手机号码查找用户
//			if(user == null){ // user 为空 说明该手机号码没有被使用
//				json.addProperty("succ", true);
//			} else { // 该手机号码被使用
//				json.addProperty("error", false);
//			} 
//			return json;
//		}
		
		
		// 车辆预订首页
		@RequestMapping("/carBookingIndex")
		public String carBookingIndex(Map<Object,Object> model,@RequestParam(value="cityCode",required=false) String cityCode,
				HttpSession session){
			
			String sessionCityCode = getSessionCityCode(session);
			cityCode = sessionCityCode = getSessionCityCode(session);
			if(StringUtils.isBlank(sessionCityCode) && StringUtils.isBlank(cityCode)){
				cityCode = "330100";
			} else if (StringUtils.isNotBlank(cityCode)) {
				session.setAttribute(SESSION_CITY_CODE_KEY,cityCode);
			}
			
			
			List<City> cityList=cityService.getCityListWithState(1);
			model.put("cityList", cityList);
			model.put("currCity", getCurrCity(sessionCityCode));
			
//			JsonObject json=new JsonObject();
//			json.addProperty("totalPages", pager.getTotalPages());
//			json.addProperty("currentPage", pager.getCurrentPage());
//			json.addProperty("totalCount", pager.getTotalCount());
//			List<GoodsPro> list=pager.getItemList();
//			if(list!=null && list.size()>0){
//			JsonArray array=new JsonArray();
//				for(GoodsPro t : list){
//					JsonObject obj = new JsonObject();
//					obj.addProperty("id", t.getId());	
//					JsonArray arr = new JsonParser().parse(t.getUrlList()).getAsJsonArray();
//					obj.add("urlList", arr);//商品图片
//					obj.addProperty("name", t.getName());//商品名字
//					
//					array.add(obj);
//				}
//				json.add("arrays", array);
//			}
//			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
//			return   ""+json  ;
			
			
			JsonObject json=new JsonObject();
			
			List<County> countyList=countyService.getCountryListWithState(cityCode);
			JsonArray countyArray=new JsonArray();
			for(County ct:countyList){
					JsonObject countyObj = new JsonObject();
					
					countyObj.addProperty("code", ct.getCode());
					countyObj.addProperty("name", ct.getName());
					
					JsonArray stationArray=new JsonArray();
					
					List<Station> stationList=stationService.getListByProvinceCode(ct.getCode());
					
					for(Station st:stationList){
						JsonObject stationObj = new JsonObject();
						stationObj.addProperty("id", st.getId());
						stationObj.addProperty("name", st.getName());
						stationArray.add(stationObj);
					}
					//countyObj.addProperty("stationArray", stationArray.toStr);
					countyObj.add("stationArray",stationArray);
					
					countyArray.add(countyObj);
			}
			json.add("countyArray",countyArray);	
		
			model.put("json", json.toString());		
			return "/web/index/2.0.0cheliang_order";
		}
		
		
		
		
				
				
				//车辆预订列表
				@RequestMapping(value="/carlist",produces = "application/json; charset=utf-8")
				public @ResponseBody String findCarList(
						@RequestParam(value="pager",required = false ) Pager<Car> pager,
						@RequestParam(required=false) Integer stationId,
						@RequestParam(required=false) String  userRole,
						@RequestParam(required=false) String  priceType,
						@RequestParam(required=false) String type,
						@RequestParam(required=false) String model,
						@RequestParam(required=false) String brend,
						@RequestParam(required=false) String orderType,
						HttpSession session, HttpServletRequest request) {
						if(pager==null){
							pager=new Pager<Car>();
						}
						if(StringUtils.isNotBlank(stationId.toString()))pager.getSearchMap().put("stationId", stationId.toString());
						if(StringUtils.isNotBlank(userRole))pager.getSearchMap().put("userRole", userRole);
						if(StringUtils.isNotBlank(type))pager.getSearchMap().put("type", type);
						if(StringUtils.isNotBlank(model))pager.getSearchMap().put("model", model);
						if(StringUtils.isNotBlank(brend))pager.getSearchMap().put("brend", brend);
						if(StringUtils.isNotBlank(orderType))pager.getSearchMap().put("orderType", orderType);
						pager = carService.getPager(pager);
						JsonObject json=new JsonObject(); 
						json.addProperty("totalPages", pager.getTotalPages());
						json.addProperty("currentPage", pager.getCurrentPage());
						json.addProperty("totalCount", pager.getTotalCount());
						JsonArray carArray=new JsonArray();
						
						List<Car> list=pager.getItemList();
						for(Car car:list){
							
							JsonObject obj = new JsonObject();
							JsonArray arr = new JsonParser().parse(car.getUrlList()).getAsJsonArray();
							
							Station station=stationService.select(car.getStationId());
							car.setStation(station);
							obj.addProperty("name", car.getName());
							
							//驱动方式  手动  等
							obj.addProperty("gearbox", car.getGearbox());
							obj.addProperty("color", car.getColor());
							obj.addProperty("model", car.getModel());
							obj.addProperty("stationName", car.getStation().getName());
							//`dayprice` float(10,0) DEFAULT NULL COMMENT '日租费用',
							//`monthprice` float(10,0) DEFAULT NULL COMMENT '月租单价',
							//`seasonprice` float(10,0) DEFAULT NULL COMMENT '季租单价',
							//`yearprice` float(10,0) DEFAULT NULL COMMENT '年租单价',
							obj.addProperty("dayprice", car.getDayprice());
							obj.addProperty("monthprice", car.getMonthprice());
							obj.addProperty("seasonprice", car.getSeasonprice());
							obj.addProperty("yearprice", car.getYearprice());
							
							JsonArray a = new JsonArray();
							for(JsonElement li : arr){
								a.add(new JsonPrimitive(TagUtils.getFileFullPath(li.toString().replace("\"", ""))));
							}
							json.add("urlList", a);
						    carArray.add(obj);
							
						}
						json.add("carArray", carArray);
						
					    return json.toString();
				}

}



